package cn.iocoder.yudao.module.member.alliance.api;

import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.api.member.alliance.CloudAllianceUserApi;
import cn.iocoder.yudao.module.api.member.alliance.enums.CloudAllianceTypeEnum;
import cn.iocoder.yudao.module.api.member.alliance.vo.CloudAllianceUserVO;
import cn.iocoder.yudao.module.member.alliance.dal.dataobject.CloudAllianceUserDO;
import cn.iocoder.yudao.module.member.alliance.service.AppCloudAllianceUserService;
import jakarta.annotation.Nullable;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

/**
 * 云盟商的 API 实现类
 *
 * @author 山野羡民
 */
@Service
@Validated
public class CloudAllianceUserApiImpl implements CloudAllianceUserApi {

    @Resource
    private AppCloudAllianceUserService appCloudAllianceUserService;

    @Override
    public CloudAllianceUserVO getCloudAllianceUser(Long userId) {
        CloudAllianceUserDO vipUserDO = appCloudAllianceUserService.getOrCreate(userId);
        return BeanUtils.toBean(vipUserDO, CloudAllianceUserVO.class);
    }

    @Override
    public boolean validCloudAlliance(Long userId, @Nullable CloudAllianceTypeEnum type) {
        return appCloudAllianceUserService.isValid(userId, type);
    }

}
